let ajaxtime =0
export const request=(params)=>{
    //判断请求路径有没有/my/ 如果有说明要携带请求头
    let header = {...params.header}
    if(params.url.includes('/my/')){
        header["Authorization"] = wx.getStorageSync('token');  
    }
    ajaxtime++;
    wx.showLoading({
        title:'加载中' ,
        mask: true,
    }); 
    const baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'
    return new Promise((resolve,reject)=>{
        wx.request({
            ...params,
            header,
            url:baseUrl+params.url,
            success: (result) => {
                return resolve(result.data.message)
            },
            fail: (err) => {
                return reject(err)
            },
            complete(){
                ajaxtime--;
                if(ajaxtime==0){
                    wx.hideLoading();
                }
            }
        });
          
    })
}